﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style.css">
<link href="../tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="../tablecloth/tablecloth.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php	

	include("../inc/joomlaInt_admin.php");
	include("../inc/inc_configuration.php");

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{	
	
	$q="SELECT gid FROM $tbl_users WHERE id=$jUser";
					$qe=mysql_query($q);
					$qeo=mysql_fetch_object($qe);
					
					$gid=$qeo->gid;
					
					if ($gid!=$admingroup)
					{
						echo "Du bist kein Admin!";
						break;
					}
					
	echo "<h1>Trainer</h1>";
	
	echo "<form action='combination_anlegen.php' method='post'>
			<table>
				<tr>
					<th colspan='2'>Neue Combination</th>
				</tr>";
	
	
	//User
	
	$uq="SELECT * FROM $tbl_users";
	$uqe=mysql_query($uq);
	
	$option="";
	
	while ($row=mysql_fetch_object($uqe))
	{
		$uid=$row->id;
		$un=$row->username;
		
		$option.="<option value='$uid'>$un</option>";
	}
	
	$tin="	<select name='user'>
				$option
			</select>";
			
	echo "	<tr>
				<td>User:</td>
				<td>$tin</td>
			</tr>";
			
	//Teams		
			
	$uq="SELECT * FROM $tbl_teams WHERE vergeben=0";
	$uqe=mysql_query($uq);
	
	$option="";
	
	while ($row=mysql_fetch_object($uqe))
	{
		$uid=$row->id;
		$un=$row->name;
		
		$option.="<option value='$uid'>$un</option>";
	}
	
	$tin="	<select name='team'>
				$option
			</select>";
			
	echo "	<tr>
				<td>Team:</td>
				<td>$tin</td>
			</tr>";
			
	echo "	<tr>
				<td colspan='2'><input type='submit' value='Anlegen'></td>
			</tr>";
			
	echo "</table></form>";
	
	
	
	echo "<table>
			<tr>
				<th></th>
				<th>Team</th>
				<th>User</th>
				<th>Antritt</th>
				<th>Letztes Spiel</th>
				<th>Entlassen</th>
			</tr>";
	

	$mq="	SELECT
				c.id,
				u.username,
				t.name,
				c.joinDate,
				c.lastMatchDate,
				t.id AS tid
			FROM
				$tbl_combinations c,
				$tbl_teams t,
				$tbl_users u
			WHERE
				c.active=1 AND
				c.userId=u.id AND
				c.teamId=t.id
			ORDER BY
				c.lastMatchDate ASC";

	
	$mqe=mysql_query($mq);
				
	while ($row=mysql_fetch_object($mqe))
	{
		$cid=$row->id;
		$un=$row->username;
		$tn=$row->name;
		$tid=$row->tid;
		$jd=$row->joinDate;
		$lmd=$row->lastMatchDate;
		
		if ($lmd==0)
		{
			$lmd="(-)";
		}
		else
		{
			$lmd=date("d.m.y - H:i",$lmd);
		}
		$jd=date("d.m.y - H:i",$jd);
		
		
		$entlassen=	"	<form action='entlassen.php' method='post'>
							<input name='combination' type='hidden' value='$cid'>
							<input name='reasonId' type='hidden' value='2'>
							<input type='submit' value='ENT' >
						</form>
					";
					//
		
		echo "	<tr>
					<td><a href='team_kader.php?team=$tid'><img src='../img/logos/",$tid,".png' width='35' height='35' alt=''></a></td>
					<td>$tn</td>
					<td>$un</td>	
					<td>$jd</td>
					<td>$lmd</td>
					<td>$entlassen</td>
				</tr>";	
	}
	
	echo "</table>";
	
	echo "<br><br><center><a href='../lima.php' class='button zurueck'>Zurück</a>";
}	
?>

</body>
</html>